package com.xique.park.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xique.park.bean.domain.AccessDevice;
import com.xique.park.mapper.AccessDeviceMapper;
import com.xique.park.service.service.IAccessDeviceService;
import org.springframework.stereotype.Service;

/**
 * AccessDeviceServiceImpl
 *
 * @author xique
 */
@Service
public class AccessDeviceServiceImpl extends ServiceImpl<AccessDeviceMapper, AccessDevice> implements IAccessDeviceService {

    /**
     * 设备状态离线
     */
    public int getAccessDeviceOffline(Long parkId) {
        QueryWrapper<AccessDevice> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("count(*) as countAll");
        queryWrapper.eq("park_id", parkId);
        queryWrapper.eq("status", "normal");
        queryWrapper.eq("online_status", "offline");
        AccessDevice ord = this.baseMapper.selectOne(queryWrapper);
        return ord.getCountAll();
    }

    /**
     * 设备状态在线
     */
    public int getAccessDeviceOnline(Long parkId) {
        QueryWrapper<AccessDevice> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("count(*) as countAll");
        queryWrapper.eq("park_id", parkId);
        queryWrapper.eq("status", "normal");
        queryWrapper.eq("online_status", "online");
        AccessDevice ord = this.baseMapper.selectOne(queryWrapper);
        return ord.getCountAll();
    }

}
